package swing;

import utils.CommonUtils;

import javax.swing.*;
import java.awt.*;

/**
 * @version V1.0
 * @Title:
 * @Package
 * @Description: 右侧的面板，包含查询区和输入区
 * @author: GaleBlade
 * @date:
 */
public class CommonPanel extends JPanel {

    private JPanel keyPanel = new JPanel();
    private JPanel valuePanel = new JPanel();
    private JLabel keyLabel = new JLabel("key:", JLabel.LEFT);
    private JLabel valueLabel = new JLabel("value:", JLabel.LEFT);
    private JTextArea keyArea = new JTextArea(2,45);
    private JTextArea valueArea = new JTextArea(6,45);
    private JScrollPane valueScroll;

    public CommonPanel(){
        this.setLayout(null);
        this.setBackground(Color.GRAY);
        initComponents();
        addComponents();
    }

    public void addComponents(){
        keyPanel.add(keyLabel);
        keyPanel.add(keyArea);
        valuePanel.add(valueLabel);
        valuePanel.add(valueScroll);
        this.add(keyPanel);
        this.add(valuePanel);
    }

    public void initComponents(){
        Font font = new Font("Menu.font", Font.PLAIN, 14);
        keyPanel.setBounds(10,0,430,50);
        valuePanel.setBounds(10,50,430,260);
        keyPanel.setBackground(Color.GRAY);
        valuePanel.setBackground(Color.GRAY);
        keyLabel.setForeground(Color.WHITE);
        valueLabel.setForeground(Color.WHITE);
        keyArea.setBackground(new Color(191,191,191));
        valueArea.setBackground(new Color(191,191,191));
        keyLabel.setFont(font);
        valueLabel.setFont(font);
        keyArea.setFont(font);
        valueArea.setFont(font);
        keyPanel.setLayout(null);
        valuePanel.setLayout(null);
        keyLabel.setBounds(0,0,430,30);
        keyArea.setBounds(0,30,430,20);
        valueLabel.setBounds(0,0,430,30);
        valueArea.setBounds(0,30,430,210);
        valueArea.setLineWrap(true);
        valueScroll = new JScrollPane(valueArea);
        valueScroll.setBounds(0,30,430,210);
    }

    public void setEditable(Boolean b){
//        keyArea.setEditable(b);
        valueArea.setEditable(b);
    }

    public void setKeyArea(String key){
        keyArea.setText(key);
    }

    public void setValueArea(String value){
        valueArea.setText(CommonUtils.formatJSON(value));
    }

    public String getField(){
        return keyArea.getText();
    }

    public String getValue(){
        return valueArea.getText();
    }

}
